import 'package:flutter/material.dart';
import 'package:flutterlib/common/constants/constants.dart';
import 'package:flutterlib/common/utils/utils.dart';


class TextInputDialog extends StatefulWidget {

  static Future<String> show(BuildContext context) => showDialog<String>(
    context: context,
    builder: (_) => TextInputDialog(),
    barrierDismissible: false,
  );

  @override
  State<StatefulWidget> createState() => TextInputDialogState();
}

class TextInputDialogState extends State<TextInputDialog> {
  final TextEditingController _textEditingController = TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _textEditingController?.dispose();
    super.dispose();
  }


  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Stack(
            children: <Widget>[
              Container(
                padding: EdgeInsets.symmetric(vertical: 16.h),
                width: Screens.width - 100.w,
                decoration: BoxDecoration(
                  color: Theme.of(context).canvasColor,
                  borderRadius: BorderRadius.circular(12.w),
                ),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    Container(
                      margin: EdgeInsets.fromLTRB(20, 20, 20, 0),
                      padding:
                          EdgeInsets.symmetric(horizontal: 10.w, vertical: 10.w),
                      height: 100.h,
                      width: Screens.width - 100.w,
                      decoration: BoxDecoration(
                        border: Border.all(
                            color: currentThemeColor),
                      ),
                      child: TextField(

                        autofocus: true,
                        controller: _textEditingController,
                        cursorColor: currentThemeColor,
                        decoration: const InputDecoration(
                          border: InputBorder.none,
                          contentPadding: EdgeInsets.zero,
                          hintText: '请输入申请原因',
                          hintStyle: TextStyle(textBaseline: TextBaseline.alphabetic),
                        ),
                        textInputAction: TextInputAction.send,
                        style: Theme.of(context).textTheme.bodyText2.copyWith(
                          fontSize: 20.sp,
                          textBaseline: TextBaseline.alphabetic,
                        ),
                        scrollPadding: EdgeInsets.zero,
                        maxLines: 20,
                        onSubmitted: (_){
                          Navigator.of(context).pop(_textEditingController.text);
                        }

                      ),
                    ),
                    SizedBox(height: 10,),
                    RaisedButton(
                      textColor: Colors.white,
                      color: Colors.green,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.all(
                              Radius.circular(16),
                              )),
                      child: Text("申请"),
                      onPressed: () {
                        Navigator.of(context).pop(_textEditingController.text);
                      },
                    )
                  ],
                ),
              ),
              Positioned(
                top: 10.w,
                right: 20.w,
                child: GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  child: const Icon(Icons.close),
                  onTap: (){
                    Navigator.of(context).pop();
                  }
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
